export default{
	namespaced:true,
	state:()=>({
		settings:JSON.parse(uni.getStorageSync("settings")||"[]"),
		storageSize:uni.getStorageSync("storageSize")
	}),
	mutations:{
		addToSetting(state,setting){
			//判断当前settion中是否存在这个配置，如果存在则将最新的添加进去。
			const findResult = state.settings.findIndex((x) => x.k == setting);
			if(findResult == -1){
				state.settings.push(setting); 
				//通过commit 方法，调用m_setting命名空间下的saveSettingToStorage方法将settings保存到storage中
			    this.commit("m_setting/saveSettingToStorage");
			}
		},
		saveSettingToStorage(state){
			uni.setStorageSync("settings",JSON.stringify(state.settings))
		},
		delSetting(state){
			uni.removeStorageSync("settings")
		},
		/**
		 * 修改storageSize的值
		 */
		updateStorageSize(state,size){
			state.storageSize = size;
			this.commit("m_setting/saveStorageSize");
		},
		/**
		 * 把Storage保存到Storage中
		 */
		saveStorageSize(state){
			uni.setStorageSync("storageSize",state.storageSize)
		}
	},
	getters:{
		/**
		 * 获取某个指定的Setting
		 * @param {Object} state 上下文对象
		 */
		settingk(state){
			let key_setting = {};
			for(let item in state.settings){
				key_setting[state.settings[item]['k']] = state.settings[item]["val"]
			}
			return key_setting;
		},
		
	}
}